package com.stud.common.core.page;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

import java.util.Objects;

/**
 * 分页属性
 *
 * @author Stud
 */
@Schema(description = "分页属性")
@Getter
@Setter
public class PageDomain {
    /**
     * 当前记录起始索引
     */
    @Schema(description = "当前记录起始索引")
    private Integer pageNum;

    /**
     * 每页显示记录数
     */
    @Schema(description = "每页显示记录数")
    private Integer pageSize;

    /**
     * 排序列
     */
    @Schema(description = "排序列")
    private String orderByColumn;

    /**
     * 排序
     */
    @Schema(description = "排序")
    private String orderBy;

    /**
     * 排序的方向desc或者asc
     */
    @Schema(description = "排序的方向desc或者asc")
    private String isAsc = "asc";

    /**
     * 分页参数合理化
     */
    @Schema(description = "分页参数合理化")
    private Boolean reasonable = true;

    public int getPageStart() {
        if (Objects.isNull(pageNum) || pageNum < 1) {
            pageNum = 1;
        }
        return (pageNum - 1) * pageSize;
    }
}
